/**
 * 工单API
 *
 * @Date 2021/4/5 12:39
 * @author 周世焕
 */

import axios from "@/libs/api.request";
import qs from 'qs'

/**
 * 保存工单
 */
export function saveTicket(data) {
    return  axios.request({
        url: '/v1/ticket',
        data: data,
        method: 'post',
        errMsg: '保存工单'
    })
}

/**
 * 分配工单
 */
export function assignTicket(ticketId,assignee,assigneeName) {
    return  axios.request({
        url: '/v1/ticket/assign',
        params: {ticketId,assignee,assigneeName},
        method: 'post',
        errMsg: '分配工单'
    })
}

/**
 * 分配工单批量
 * @returns {AxiosPromise}
 */
export function assignBatch(ticketId,assignee,assigneeName) {
    return  axios.request({
        url: '/v1/ticket/assign/batch',
        params:{ticketId,assignee,assigneeName},
        method: 'post',
        errMsg: '分配工单出错',
        paramsSerializer: params => {
            return qs.stringify(params, { indices: false })
        }
    })
}

/**
 * 改变工单状态
 */
export function changeTicketStatus(ticketId,old,now) {
    return  axios.request({
        url: '/v1/ticket/status',
        params: {ticketId,old,now},
        method: 'post',
        errMsg: '更改工单状态'
    })
}

/**
 * 查询所有工单
 * @returns {AxiosPromise}
 */
export function findAllTicket() {
    return  axios.request({
        url: '/v1/ticket/all',
        method: 'get',
        errMsg: '查询工单'
    })
}

/**
 * 查询部门工单
 * @returns {AxiosPromise}
 */
export function findDeptTicket() {
    return  axios.request({
        url: '/v1/ticket/dept',
        method: 'get',
        errMsg: '查询工单'
    })
}

/**
 * 查询我的工单
 * @returns {AxiosPromise}
 */
export function findMineTicket(status) {
    return  axios.request({
        url: '/v1/ticket/mine',
        params:{status},
        method: 'get',
        errMsg: '查询工单'
    })
}

/**
 * 根据Id查询工单
 * @returns {AxiosPromise}
 */
export function findById(ticketId) {
    return  axios.request({
        url: '/v1/ticket',
        params:{ticketId},
        method: 'get',
        errMsg: '获取工单'
    })
}

/**
 * 查询工单历史
 * @param ticketId
 * @returns {AxiosPromise}
 */
export function findHistoryByTicketId(ticketId) {
    return  axios.request({
        url: '/v1/ticket/history',
        params:{ticketId},
        method: 'get',
        errMsg: '查询工单历史'
    })
}

/**
 * 查询客户工单
 * @returns {AxiosPromise}
 */
export function findCustomerTicket(customerId) {
    return  axios.request({
        url: '/v1/ticket/customer',
        params:{customerId},
        method: 'get',
        errMsg: '查询客户工单'
    })
}


/**
 * 删除工单（批量）
 * @returns {AxiosPromise}
 */
export function deleteByIdBatch(ticketId) {
    return  axios.request({
        url: '/v1/ticket/batch',
        params:{ticketId},
        method: 'delete',
        errMsg: '删除工单出错',
        paramsSerializer: params => {
            return qs.stringify(params, { indices: false })
        }
    })
}

/**
 * 删除工单
 * @returns {AxiosPromise}
 */
export function deleteById(ticketId) {
    return  axios.request({
        url: '/v1/ticket',
        params:{ticketId},
        method: 'delete',
        errMsg: '删除工单出错',
    })
}
